
var app = getApp()
Page({

  data: {
    password:'',
    confirmPassword:'',
    regAccountId:'',
    type:''  //0是重置密码 1是注册
  },

  onLoad: function (options) {
    this.setData({
      regAccountId:options.regAccountId,
      type:options.type?options.type:1
    })
  },
  getPassword(e){
    this.setData({
      password:e.detail.value
    })
  },
  confirmPassword(e){
    this.setData({
      confirmPassword:e.detail.value
    })
  },
  confirm(){
    let that = this
    if (this.data.password==''||this.data.confirmPassword=='') {
      app.errorMsg('请输入密码')
    }else{
      if (this.data.password==this.data.confirmPassword) {
        let data = {
          regAccountId:this.data.regAccountId,
          pwd1:this.data.password,
          pwd2:this.data.confirmPassword
        }
        console.log(data)
        app.request('wx_app/agent_account/setPassword',data,'GET').then(res=>{
          console.log(res)
          if (res.code==1) {
            if (that.data.type==0) {
              wx.showToast({
                title:'设置成功'
              })
            }else{
              wx.showToast({
                title:'注册成功'
              })
            }
            setTimeout(function(){
              wx.removeStorage({
                key:'memInfo',
                success(){
                  wx.switchTab({
                    url:'../../my/purchase/purchase'
                  })
                }
              })
            },1000)

          }else{
            app.errorMsg(res.message)
          }
        })
      }else{
        app.errorMsg('两次输入的内容不一致')
      }
    }
  },
  //跳过密码
  jump(){
    wx.switchTab({
      url:'../../my/purchase/purchase'
    })
  }
})
